<template>
    <div class="diskInfoWrap">
        <el-button type="primary" size="small" @click="getDiskInfo" icon="el-icon-upload" style="margin: 4px 0 12px" v-if="hasAuth('VMS_ENTERPRISE_RISK_ADD')">
            获取纳税人风险信息
        </el-button>
        <tableList
            border
            maxHeight="120"
            :pageNumber="pages.current"
            :pageSize="pages.size"
            :total="pages.total"
            :keySet="keySet"
            :tableData="listDetails"
            :paginationShow="false"
        ></tableList>

        <div class="head" style="margin-top: 16px">
            <p class="colCLas"></p>
            <p class="info">获取记录</p>
        </div>

        <el-form
            :inline="true"
            :model="searchParams"
            class="formInline"
            size="small"
            label-width="80px"
        >
            <el-form-item label="操作时间" >
                <el-date-picker
                    style="width: 375px;"
                    v-model="dateRange"
                    type="datetimerange"
                    start-placeholder="选择开始日期"
                    end-placeholder="选择结束日期"
                    @change="changeDate"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    :default-time="['00:00:00', '23:59:59']">
                </el-date-picker>
            </el-form-item>
            <!-- <el-form-item label="申请时间">
                <el-date-picker
                    v-model="date1"
                    type="datetime"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    placeholder="选择申请时间"
                    default-time="00:00:00"
                ></el-date-picker>
            </el-form-item>
            <el-form-item label="至" label-width="20px">
                <el-date-picker
                    v-model="date2"
                    type="datetime"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    placeholder="选择日期时间"
                    default-time="23:59:59"
                ></el-date-picker>
            </el-form-item> -->

            <el-form-item label="执行状态" style="max-width: 240px">
                <el-select
                    style="width: 160px"
                    v-model="searchParams.select1"
                    placeholder="请选择"
                >
                    <el-option label="成功" value="01"></el-option>
                    <el-option label="失败" value="02"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item
                label="操作人"
                style="max-width: 240px"
                label-width="80px"
            >
                <el-input
                    style="width: 160px"
                    v-model="searchParams.input1"
                    :maxlength="50"
                    placeholder="请输入"
                ></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit">查询</el-button>
                <el-button type="primary" @click="onResize">重置</el-button>
            </el-form-item>
        </el-form>

        <tableList
            :data="listDetails2"
            :showIndex="true"
            :loading="loading2"
            border
            :heightMin="340"
            :total="pages2.total"
            :keySet="keySet2"
            :tableData="listDetails2"
            :paginationShow="true"
            :pageNumber="pages2.current"
            :pageSize="pages2.size"
            @handleSizeChange="handleSizeChange2"
            @handleCurrentChange="handleCurrentChange2"
        ></tableList>
    </div>
</template>
  
<script>
import mixinTable from '@/mixin/mtable.js'
import tableList from '@/components/tableList/index.vue'
import { throttle } from 'lodash'
import { queryVmsEnterpriseInfoRisk , queryVmsEnterpriseInfoRiskLog ,getVmsEnterpriseInfoRiskByLq } from '@/api/vmsEnterpriseInfoRisk.js'

export default {
    name: 'diskInfo',
    mixins: [mixinTable],
    data() {
        return {
            listDetails: [],
            keySet: [
                {
                    label: '纳税人识别号',
                    englishName: 'nsrsbh',
                    minWidth:150
                },
                {
                    label: '风险纳税人类型',
                    englishName: 'fxnsrlx',
                    minWidth:150
                },
                {
                    label: '纳税人信用等级',
                    englishName: 'nsrxydj',
                    width: 150
                },
                {
                    label: '纳税人预警级别',
                    englishName: 'nsryjjb',
                },
                {
                    label: '风险纳税人标志',
                    englishName: 'fxnsrbz',
                },
            ],

            // date1: '',
            // date2: '',
            dateRange: ['', ''],
            listDetails2: [],
            keySet2: [
                {
                    label: '操作时间',
                    englishName: 'createTime',
                    width:150
                },
                {
                    label: '执行状态',
                    englishName: 'operateStatus',
                    width:80
                },
                {
                    label: '执行结果',
                    englishName: 'operateMsg',
                },
                {
                    label: '操作人',
                    englishName: 'createUsername',
                    width:150
                },
            ],
            loading2: false,
        }
    },
    methods: {
        changeDate(date){
            if(date === null){
                setTimeout(()=>{
                    this.dateRange = ['','']
                },200)
            }else{
                // this.$store.commit('flowInvoice/ChangeFLowForm',{
                //     ...this.$store.state.flowInvoice.flowForm,
                //     startTime: date[0],
                //     endTime: date[1],

                // })
            }
        },
        onSubmit() {

            let params = {
                startDate: this.dateRange[0],
                endDate: this.dateRange[1],
                select1: this.searchParams.select1,
                input1: this.searchParams.input1,
            }
            this.pages2.current = 1;
            this.getList2(params)
        },
        onResize() {
            this.onResizeFn()
            // this.date1 = ''
            // this.date2 = ''
            this.dateRange = ['', '']
            this.getList2()
        },
      handleSizeChange2(val){
        this.pages2.current = 1;
        this.pages2.size = val;
        this.getList2()
      },
      handleCurrentChange2(val){
        this.pages2.current = val;
        this.getList2()
      },
        getList: throttle(async function (params) {
            let { data, code, message } = await queryVmsEnterpriseInfoRisk()
            if (code == 200) {
                this.listDetails = [data]
            } else {
                // this.$message({
                //     type: 'success',
                //     message: message,
                // })
            }
        }, 500),
        getList2: throttle(async function () {
            this.loading2 = true
            let { data, code, message } = await queryVmsEnterpriseInfoRiskLog(
                {
                    startTime: this.dateRange[0] || '',
                    endTime: this.dateRange[1] || '',
                    operateStatus: this.searchParams.select1,
                    createUsername: this.searchParams.input1,

                    pageNo: this.pages2.current,
                    pageSize: this.pages2.size,
                }
            )
            if (code == 200) {
                this.loading2 = false
                this.listDetails2 = data.records.map(item=>{
                    return {
                        ...item
                    }
                })
                this.pages2.total = data.total
                this.pages2.current = data.current
                this.pages2.size = data.size
            } else {
                this.loading2 = false
                // this.$message({
                //     type: 'success',
                //     message: message,
                // })
            }
        }, 500),
        getDiskInfo() {
            this.$alert('是否调用接口获取纳税人风险信息？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                showCancelButton: true,
                type: 'warning',
            })
                .then(async () => {
                    let { code, message } = await getVmsEnterpriseInfoRiskByLq()

                    if (code == 200) {
                        this.getList()
                        this.getList2()
                    } 
                })
                .catch(() => {
                    // this.$message({
                    //     type: 'info',
                    //     message: '已取消',
                    // })
                })
        },
    },
    mounted() {
        this.getList()
        this.getList2()
    },
    components: {
        tableList,
    },
    computed:{

    }
}
</script>
  
  <style lang = "scss" scoped>
@import '@/style/variables.scss';
.diskInfoWrap {
    box-sizing: border-box;
    height: 100%;
    overflow: auto;
    .head {
        display: flex;
        height: 18px;
        align-items: center;
        margin-bottom: 12px;
        .colCLas {
            width: 4px;
            height: 100%;
            background-color: $allBg;
            margin-right: 12px;
        }
        .info {
            height: 100%;
            display: flex;
            align-items: center;
        }
    }
}
</style>
  